package com.kellycheung.chicken_go_go;

import android.graphics.Canvas;
import android.graphics.Paint;

import com.kellycheung.chicken_go_go.GameScene.GameSceneStatus;

abstract public class BaseObject implements Comparable<BaseObject> {
	public enum GOAnchor {
		UpLeft(7), Up(8), UpRight(9)
		,Left(4), Center(5), Right(6)
		,DownLeft(1), Down(2), DownRight(3)
		;
		
		public static GCoordinate convCoord( GOAnchor p_goa , GCoordinate p_gc , GRectangle p_gr ) {
			GCoordinate gcNew = new GCoordinate( p_gc );
			float fW = p_gr.fRight - p_gr.fLeft;
			float fH = p_gr.fDown - p_gr.fUp;
			
			switch ( p_goa ) {
			case Up:
			case Center:
			case Down:
				gcNew.fX = gcNew.fX - fW/2f; 
				break;
			case UpRight:
			case Right:
			case DownRight:
				gcNew.fX = gcNew.fX - fW; 
				break;
			default:
				break;
			}
			
			switch ( p_goa ) {
			case Left:
			case Center:
			case Right:
				gcNew.fY = gcNew.fY - fH/2f; 
				break;
			case DownLeft:
			case Down:
			case DownRight:
				gcNew.fY = gcNew.fY - fH; 
				break;
			default:
				break;
			}
			
			return gcNew;
		}
		
		@SuppressWarnings("unused")
		private final int iVal;
		
		GOAnchor( int p_iVal ) {
			this.iVal = p_iVal;
		}
	}
	
	protected GameScene gsScene;
	protected GCoordinate gcCoord;
	
	protected int iZOrder;
	protected GOAnchor goaAnchor;
	protected GameSceneStatus gssAllowStatus; 
	protected String sObjName;

	public BaseObject( GameScene p_gsScene , int p_iZOrder , GOAnchor p_goa , float p_fX , float p_fY ) {
		try
		{
			this.gsScene = p_gsScene;
			this.iZOrder = p_iZOrder;
			this.goaAnchor = p_goa;
			this.gcCoord = new GCoordinate( p_fX , p_fY );
			this.gssAllowStatus = GameSceneStatus.none;
			this.sObjName = "";
		} catch ( Exception p_e ) {
			// TODO Auto-generated catch block
			GameUtil.LogMsg( this , "BaseObject" );
			GameUtil.ErrorHandler( this , p_e );
		}
	}
	
	@Override
	public int compareTo( BaseObject p_bo ) {
		try {
			if ( this.iZOrder < p_bo.iZOrder ) {
				return 1;
			} else if ( this.iZOrder > p_bo.iZOrder ) {
				return -1;
			}
		} catch ( Exception p_e ) {
			// TODO Auto-generated catch block
			GameUtil.LogMsg( this , "BaseObject.compareTo" );
			GameUtil.ErrorHandler( this , p_e );
		}
		
		return 0;
	}
	
	public void destroy() {
		try {
			this.gcCoord = null;
			this.gsScene = null;
			this.sObjName = null;
		} catch ( Exception p_e ) {
			// TODO Auto-generated catch block
			GameUtil.LogMsg( this , "BaseObject.destroy" );
			GameUtil.ErrorHandler( this , p_e );
		}
	}
	
	abstract public void draw( Canvas p_c , Paint p_p );
	
	abstract public void gameLoopLogic();
	
	abstract public void postGameLoopLogic();
	
	abstract public void preGameLoopLogic();
	
}
